extends Node

class_name Task

enum TaskType {
	base,
	fundItems,
	walkTo,
	pickUp,
	eat,
	manipulate,
	harvest
}

var taskName: String
var type: TaskType = TaskType.base

# 任务执行队列
var subTasks = []
var current: int = 0 # 当前执行序列号

#目标物品
var targetItem
var itemType

# 任务执行完成
func isFinished() -> bool:
	return current == len(subTasks)

# 任务完成
func finish():
	current = len(subTasks)

# 获取当前任务
func getCurrentTask():
	return subTasks[current]

# 完成当前子任务
func finishSubTask():
	current += 1

# 发现物品
func foundItem(item: Item):
	finishSubTask()
	getCurrentTask().targetItem = item

# 到达目的地
func reachedDestination():
	finishSubTask()
	getCurrentTask().targetItem = subTasks[current - 1].targetItem

# 自动寻找食物吃下
func addfoundFoodEatTask():
	taskName = '找到一些食物，并吃下它们！'
	var subTask = Task.new()
	subTask.type = TaskType.fundItems
	subTask.itemType = Items.ItemTypes.food
	subTasks.append(subTask)

	subTask = Task.new()
	subTask.type = TaskType.walkTo
	subTasks.append(subTask)

	subTask = Task.new()
	subTask.type = TaskType.pickUp
	subTasks.append(subTask)

	subTask = Task.new()
	subTask.type = TaskType.eat
	subTasks.append(subTask)

# 收获植物
func addHarvestTask(target: Item):
	var subTask = Task.new()
	subTask.type = TaskType.walkTo
	subTask.targetItem = target
	subTasks.append(subTask)

	subTask = Task.new()
	subTask.type = TaskType.harvest
	subTask.targetItem = target
	subTasks.append(subTask)